//
//  FXCNetworking.m
//  XinLangFeiBo
//
//  Created by dllo on 16/3/11.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "FXCNetworking.h"
#import "FXCAccount.h"


@implementation FXCNetworking

+ (void)getWithURL:(NSString *)url parameter:(NSDictionary *)parameter success:(successBlock)success failure:(failureBlock)failure{
    FXCAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:FXCAccountFile];
    
    NSString *urls = [NSString stringWithFormat:@"%@?access_token=%@",url,account.access_token];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil]];
    [manager GET:urls parameters:parameter progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
    }];

    
}
+ (void)postWithURL:(NSString *)url parameter:(NSDictionary *)parameter success:(successBlock)success failure:(failureBlock)failure{
    FXCAccount *account = [NSKeyedUnarchiver unarchiveObjectWithFile:FXCAccountFile];
    
    NSString *urls = [NSString stringWithFormat:@"%@?access_token=%@",url,account.access_token];
    
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    [manager.responseSerializer setAcceptableContentTypes:[NSSet setWithObjects:@"application/json", @"text/json", @"text/javascript",@"text/html",@"text/plain", nil]];
    [manager POST:urls parameters:parameter progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        

        success(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        failure(error);
    }];
    
}
@end
